/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{title}}</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <div style="margin-bottom: 20px;">
        <span>选择跟单服：</span>
        <el-select v-model="value" placeholder="请选择" @change="getSelect">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <el-button type="primary" style="margin-left: 20px;" @click="updateOrder">刷新记录</el-button>
      </div>

    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index"  width="60">
      </el-table-column>
      <el-table-column sortable prop="acc_curgolds" label="剩余金额" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="acc_golds" label="下注金额" width="100" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="game_name" label="比赛名称" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="league_name" label="赛项名称" width="150" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="order_sourcetime" label="原始时间" width="140" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="resp_gold_num" label="原始金额" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="resp_scount" label="原始数量" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="resp_sgold_num" label="原始总金额" width="110" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="resp_wagersrtype" label="下注项" width="85" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="resp_wagerswtype" label="下注类型" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="session_date" label="比赛日期" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="session_time" label="比赛时间" width="95" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable prop="trace_ordertime" label="跟单时间" width="140" header-align="center" align="center" show-overflow-tooltip>
      </el-table-column>
      <el-table-column sortable  label="是否成功" width="95" header-align="center" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          <!-- <div>{{scope.row.addTime|timestampToTime}}</div> -->
           <span v-if="scope.row.acc_curgolds > 0">成功</span>
           <span v-else style="color: red;">不成功</span>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <!-- <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination> -->

  </div>
</template>

<script>
import { ConfigGetorderlist } from '../../api/basisMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览',
      editForm: {
        id: '',
        name: '',
        payType: 1,
        partner: '',
        subMchId: '',
        appid: '',
        notifyUrl: '',
        signType: '',
        partnerKey: '',
        sellerUserId: '',
        certPath: '',
        certPassword: '',
        rsaKey: '',
        token: localStorage.getItem('logintoken')
      },
      formInline: {
        page: 1,
        limit: 10,
        machineNo: '',
        orderNo: '',
        transId: '',
        payType: 0,
        orderStatus: 0,
        token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      port: "0", ////获取当前组件接口的端口号	
      datediff : 10, ////查询时间段
      // 下拉选项
      options: [{
          value: '50010',
          label: '跟单001'
        }, {
          value: '50011',
          label: '跟单002'
        }, {
          value: '50012',
          label: '跟单003'
        }, {
          value: '50013',
          label: '跟单004'
        }, {
          value: '50014',
          label: '跟单005'
        }, {
          value: '50015',
          label: '跟单006'
        }, {
          value: '50016',
          label: '跟单007'
        }, {
          value: '50017',
          label: '跟单008'
        }, {
          value: '50018',
          label: '跟单009'
        }, {
          value: '50019',
          label: '跟单010'
        }
      ],
        value: ''
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.title = this.$route.name;
    // 组件创建时，将下拉框中默认为value设置为第一个选项的value
    if (this.options.length > 0) {
      this.value = this.options[0].value;
    }
    this.getdata(this.datediff,this.value)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata(datediff,port) {
      this.loading = true
      // 模拟数据开始
      let res = {
        code: 0,
        msg: null,
        count: 23,
        // data: [
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1526380193000,
        //     editTime: 1526380193000,
        //     orderId: 109,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: 'xxxx',
        //     transId: 'xxxx',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '退款',
        //     machineNo: '111111',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: -0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 14,
        //     openId: null,
        //     mchId: '111111111111111',
        //     subMchId: null,
        //     remark: '不允许从此IP发起交易: 101.81.251.226'
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1526380176000,
        //     editTime: 1526380176000,
        //     orderId: 108,
        //     deptId: 1,
        //     deptName: 'xxxxxx',
        //     orderNo: 'xxxx',
        //     transId: 'xxxxx',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '退款',
        //     machineNo: 'J1AX904002',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: -0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 14,
        //     openId: null,
        //     mchId: '898310154990338',
        //     subMchId: null,
        //     remark: '不允许从此IP发起交易: 101.81.251.226'
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1524921444000,
        //     editTime: 1524894094000,
        //     orderId: 107,
        //     deptId: 1,
        //     deptName: 'xxxxxx',
        //     orderNo: 'J1AX90400220180428101723945',
        //     transId: '4200000137201804287543647891',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '消费',
        //     machineNo: 'J1AX904002',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 7,
        //     openId: null,
        //     mchId: '898310154990338',
        //     subMchId: null,
        //     remark: '无法找到指定的账单'
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1521307596000,
        //     editTime: 1524641207000,
        //     orderId: 20,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '9300079120180318142634440',
        //     transId: null,
        //     payType: 0,
        //     subPayType: '0',
        //     transType: '消费',
        //     machineNo: '111111111111111',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 7,
        //     openId: null,
        //     mchId: null,
        //     subMchId: null,
        //     remark: '1111111111111111111111'
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520195909000,
        //     editTime: 1520195909000,
        //     orderId: 19,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '9300079120180305183828606',
        //     transId: null,
        //     payType: 0,
        //     subPayType: '0',
        //     transType: '消费',
        //     machineNo: '93000791',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 1,
        //     openId: null,
        //     mchId: null,
        //     subMchId: null,
        //     remark: null
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520035180000,
        //     editTime: 1520035180000,
        //     orderId: 18,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '4200000056201803031934477774',
        //     transId: '9300079120180303170851281',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '退款',
        //     machineNo: '222222222222222222',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 8,
        //     openId: null,
        //     mchId: '898310154990338',
        //     subMchId: null,
        //     remark: null
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520020261000,
        //     editTime: 1520185478000,
        //     orderId: 17,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '9300079120180303175059985',
        //     transId: '4200000072201803031887274444',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '消费',
        //     machineNo: '93000791',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 7,
        //     openId: null,
        //     mchId: '898310154990338',
        //     subMchId: null,
        //     remark: '不允许从此IP发起交易: 116.247.119.165'
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520019911000,
        //     editTime: 1520020075000,
        //     orderId: 16,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '9300079120180303174511778',
        //     transId: '4200000055201803031949877221',
        //     payType: 6,
        //     subPayType: 'WXPay',
        //     transType: '消费',
        //     machineNo: '93000791',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 1,
        //     openId: null,
        //     mchId: '898310154990338',
        //     subMchId: null,
        //     remark: null
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520019776000,
        //     editTime: 1520019776000,
        //     orderId: 15,
        //     deptId: 1,
        //     deptName: 'xxxx',
        //     orderNo: '9300079120180303174256156',
        //     transId: null,
        //     payType: 0,
        //     subPayType: '0',
        //     transType: '消费',
        //     machineNo: '93000791',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 1,
        //     openId: null,
        //     mchId: null,
        //     subMchId: null,
        //     remark: null
        //   },
        //   {
        //     addUser: null,
        //     editUser: null,
        //     addTime: 1520019729000,
        //     editTime: 1520019729000,
        //     orderId: 14,
        //     deptId: 1,
        //     deptName: '上海XX',
        //     orderNo: '9300079120180303174208429',
        //     transId: null,
        //     payType: 0,
        //     subPayType: '0',
        //     transType: '消费',
        //     machineNo: '93000791',
        //     goodsNo: '123456',
        //     goodsPrice: 0.01,
        //     payAmount: 0.01,
        //     goodsName: '可乐',
        //     aisleNo: null,
        //     orderStatus: 1,
        //     openId: null,
        //     mchId: null,
        //     subMchId: null,
        //     remark: null
        //   }
        // ]
      }
      this.loading = false
      this.listData = res.data
      this.pageparm.currentPage = this.formInline.page
      this.pageparm.pageSize = this.formInline.limit
      this.pageparm.total = res.count
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */

       ConfigGetorderlist(datediff,port)
        .then(res => {
          this.loading = false          
          console.log('ConfigGetorderlist',res.data.data.traceorders)
          
          if (res.data.data.traceorders.length == 0) {
            this.$message({
              type: 'info',
              message: '当前跟单服务器无日志！！'
            })
            this.listData = []
          } else {
            let resData = res.data.data.traceorders
            this.listData = resData
            // this.listData = res.data
            // 分页赋值
            // this.pageparm.currentPage = this.formInline.page
            // this.pageparm.pageSize = this.formInline.limit
            // this.pageparm.total = res.count
          }
        })
        .catch(err => {
          this.listData = []
          this.loading = false
          this.$message.error('日志加载失败或当前服务器无日志 ！')
        })
    },

    // 当选择服务器选择变化时获取值
    getSelect(value){
      console.log('getSelect:', value)
      this.getdata(this.datediff,value)
    },

    // 刷新页面记录
    updateOrder(){
      // 刷新页面重新读取记录
      this.getdata(this.datediff,this.value)
    },

    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示编辑界面
    handleEdit: function(index, row) {
      this.editFormVisible = true
      this.editForm = row
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          ConfigSave(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '公司保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('支付配置信息保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除公司
    deleteUser(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          ConfigDelete(row.deptId)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '公司已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('支付配置信息删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 

 